package com.example.demo2302;

import com.example.demo2302.bean.Customer;
import com.example.demo2302.bean.CustomerByAno;
import com.example.demo2302.bean.MyConfig;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@SpringBootApplication
//@GetMapping("")
@RequestMapping("/test")
public class Demo2302Application {

    public static void main(String[] args) {
        SpringApplication.run(Demo2302Application.class, args);

//        读取xml方式装载bean以及注入
//        ApplicationContext context = new ClassPathXmlApplicationContext("myApp.xml");
//       Customer customer = (Customer) context.getBean("cu2");获取spring容器中的对象
//        System.out.println("id=" + customer.getId() + "姓名=" +
//                customer.getUsername() + "密码=" + customer.getPassword());

//        基于注解方式装载bean
        ApplicationContext con = new AnnotationConfigApplicationContext(MyConfig.class);
        CustomerByAno customerByAno =  con.getBean(CustomerByAno.class);//获取spring容器中的对象
        System.out.println("id=" + customerByAno.getId() + "姓名=" +
                customerByAno.getUsername() + "密码=" + customerByAno.getPassword());




    }

    @GetMapping("/hello02")
    public String hello() {
        return "my first spring project";
    }



}
